/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package koor.action.coursework;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import koor.action.Action;
import koor.action.ActionResult;
import koor.entity.CourseWork;
import koor.persistent.CourseWorkDAO;
import koor.service.ServiceLocator;

/**
 * The
 * <code>CourseWorkListAction</code> class represents action, used to view courseWork
 * list
 *
 * @author Admin
 */
public class CourseWorkListAction implements Action {

    @Override
    public String getName() {
        return "courseWork.list";
    }

    @Override
    public ActionResult execute(HttpServletRequest request, HttpServletResponse response) {
        List<CourseWork> courseWorkList;
        if (request.getSession().getAttribute("search") == null) {
            courseWorkList = ServiceLocator.getService(CourseWorkDAO.class).findAll();
        } else {
            courseWorkList = ServiceLocator.getService(CourseWorkDAO.class).findByName((String) request.getSession().getAttribute("search"));      
        }
        request.setAttribute("courseWorkList", courseWorkList);
        return ActionResult.forward("CourseWorkView/CourseWorkListView.jsp");
    }
}
